<?php
/**
 * TW Simply Scroll Module
 *
 * @version 1.0.0
 * @copyright Copyright (C) 2010 Tomsy Web. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 * @author Tomsy Web
 *
 */
 
defined('_JEXEC') or die('Restricted access');

class modSimplyScrollHelper {
	
	static $i = 0;
	
	function increment() {
		return ++modSimplyScrollHelper::$i;
	}
	
	public function loadScripts($classname, $framerate, $speed, $horizontal, $automode, $pauseonhover, $startonload, $flickrfeed, $jsonsource, $jsonimgwidth, $jsonimgheight, $k) {
		$baseurl = JURI::base(true);
		
		JFactory::getDocument()->addStyleSheet($baseurl.'/modules/mod_twsimplyscroll/css/jquery.simplyscroll-1.0.4.css');
		JFactory::getDocument()->addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
		JFactory::getDocument()->addScript($baseurl.'/modules/mod_twsimplyscroll/js/jquery.simplyscroll-1.0.4.min.js');	
		$params = array('className' => "'$classname'", 'frameRate' => $framerate, 'speed' => $speed, 'horizontal' => $horizontal, 'autoMode' => "'$automode'", 'pauseOnHover' => $pauseonhover, 'startOnLoad' => $startonload, 'flickrFeed' => "'$flickrfeed'", 'jsonSource' => "'$jsonsource'", 'jsonImgWidth' => $jsonimgwidth, 'jsonImgHeight' => $jsonimgheight);
		function vid($var) {
			return !empty($var);
		}
		$params_filter = array_filter($params, 'vid');
		foreach ($params_filter as $key => &$value)
				$value = $key . ': ' . $value;
		$parameters = implode(', ', $params_filter);
		JFactory::getDocument()->addScriptDeclaration('$(function() {
				$("#scroller'.$k.'").simplyScroll({' .
					$parameters
				. '});
			});');
	}	
}